<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('家禽管理列表')" />
    <th:block th:include="include :: select2-css"/>
    <style>
        .img-circle {
            border-radius: 10%;
        }
    </style>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>选择农场：</label>
                                <select type="text" class="form-control" id="poultryFid" name="poultryFid">
                                    <option value="">所有</option>
                                </select>
                            </li>
                            <li>
                                <label>品种：</label>
                                <input type="text" name="poultryName"/>
                            </li>
                            <li>
                                <label>出栏状态：</label>
                                <select name="poultrySlaughterState" th:with="type=${@dict.getType('poultry_slaughter_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>领养状态：</label>
                                <select name="poultryState" th:with="type=${@dict.getType('poultry_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>允许分段加工：</label>
                                <select name="poultryIsPart" th:with="type=${@dict.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>分段模板ID：</label>
                                <input type="text" name="poultryTmpId"/>
                            </li>
                            <li>
                                <a class="btn btn-primary  btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning  btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="wechat:WxPoultry:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="wechat:WxPoultry:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js"/>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('wechat:WxPoultry:edit')}]];
        var removeFlag = [[${@permission.hasPermi('wechat:WxPoultry:remove')}]];
        var poultrySlaughterStateDatas = [[${@dict.getType('poultry_slaughter_state')}]];
        var poultryStateDatas = [[${@dict.getType('poultry_state')}]];
        var poultryIsPartDatas = [[${@dict.getType('isTrue')}]];
        var prefix = ctx + "wechat/WxPoultry";

        initTable()

        $.operate.ajaxGet(ctx + "/wechat/WxFarm/listAjax", function (result) {
            if(result.data.length==0){
                $.modal.alertError("暂无农场")
            }
            var html = "";
            for (var i = 0; i < result.data.length; i++) {
                html += "<option value='" + result.data[i].farmId + "'>" + result.data[i].farmName + "</option>";
            }
            $("#poultryFid").append(html);
        })

        //值改变事件
        $("#poultryFid").change(function () {
            $.table.search();
        })

        function initTable(){
            var options = {
                url: prefix + "/list",
                detailUrl: prefix + "/detail/{id}",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "家禽管理",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'poultryId',
                        title: '编号',
                        visible: false,
                        sortable: false
                    },
                    {
                        field: 'poultryPic',
                        title: '封面图',
                        sortable: false,
                        formatter: function (value, row, index) {
                            return $.table.imageView(value, 200);
                        }
                    },
                    {
                        field: 'wxFarm.farmName',
                        title: '农场',
                        sortable: false
                    },
                    {
                        field: 'poultryName',
                        title: '品种',
                        sortable: false
                    },

                    {
                        field: 'poultryAge',
                        title: '年龄',
                        sortable: false
                    },
                    {
                        field: 'poultryKg',
                        title: '重量（斤）',
                        sortable: false,
                        align: 'center'
                    },
                    {
                        field: 'poultryPricing',
                        title: '领养定金（元）',
                        sortable: false,
                        align: 'center'
                    },
                    {
                        field: 'poultryDayFee',
                        title: '每日费用（元）',
                        sortable: false,
                        align: 'center'
                    },
                    {
                        field: 'poultryAdminFee',
                        title: '管理费（元）',
                        sortable: false,
                        align: 'center'
                    },
                    {
                        field: 'poultrySlaughterKg',
                        title: '出栏斤数（斤）',
                        sortable: false,
                        align: 'center'
                    },
                    {
                        field: 'poultrySlaughterState',
                        title: '出栏状态',
                        align: 'center',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(poultrySlaughterStateDatas, value);
                        }
                    },
                    {
                        field: 'poultryState',
                        title: '领养状态',
                        align: 'center',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(poultryStateDatas, value);
                        }
                    },
                    {
                        field: 'poultryTime',
                        title: '创建时间',
                        sortable: false
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="openGrowth(\'' + row.poultryId + '\')">成长记录</a> ');
                            actions.push('<a class="btn btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.poultryId + '\')">编辑</a> ');
                            actions.push('<a class="btn btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.poultryId + '\')">删除</a>');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        }
        function openGrowth(id){
            $.modal.open("成长记录", ctx + "wechat/WxPoultryGrowth?pid=" + id,800,600);
        }
    </script>
</body>
</html>
